<template>
	<view>
		<u-navbar
			title="二维码"
			:autoBack="true"
			placeholder
		>
		</u-navbar>
		<scroll-view :scroll-y="true" :style="{height: scrollViewHeight, backgroundColor: appColor}">
			<template v-if="loading">
				<view style="padding: 32rpx;">
					<u-skeleton style="margin-bottom: 32rpx;" :loading="loading" avatar rows="7" v-for="i in 8" :key="i"></u-skeleton>
				</view>
			</template>
			<template v-else>
				<view style="height: 36rpx;" />
				<view style="padding: 16rpx;height: 70%;overflow: hidden;">
					<view class="shop-top">
						<text>向工作人员展示二维码</text>
					</view>
					<view class="couponQrcode-box">
						<swiper
						  indicator-dots
						  :indicator-active-color="appColor"
						  circular
						  style="height: 100%;"
						>
							<swiper-item
							  v-for="(item, index) in list"
							  :key="index"
							>
								<view class="couponQrcode-box-1">
									<view style="margin-bottom: 16rpx;">{{detail.ticketName}} ({{detail.ticketTime}})</view>
									<view style="width: 480rpx;height: 480rpx;position: relative;">
										<u--image mode="aspectFill" :src="item.qrCode" width="480rpx" height="480rpx"></u--image>
										<view v-if="item.status !== '2'" class="qr-mask">
											<text>{{item.status_dictText}}</text>
										</view>
									</view>
									<view style="padding-top: 16rpx;">{{index+1}}/{{list.length}}</view>
									<view style="padding-top: 16rpx;">核验码: {{item.code}}</view>
								</view>
							</swiper-item>
						</swiper>
						
					</view>
				</view>
			</template>
		</scroll-view>
	</view>
</template>

<script>
	import {mapState, mapActions} from 'vuex';
	import {ticketQueryById} from '@/api/me.js';
	export default {
		data() {
			return {
				screenBrightness: 0,
				num: Date.now(),
				list: [],
				detail: {},
				timer: null
			}
		},
		computed: {
			appColor() {
				return this.appPrimaryColor || '#f40215'
			},
			scrollViewHeight() {
				return this.scrollHeight - 44 + 'px';
			}
		},
		onLoad({id}) {
			let that = this;
			this.loading = true;
			uni.getScreenBrightness({
				success(res) {
					that.screenBrightness = res.value;
					that.getData(id);
					that.timer = setInterval(() => {
						that.getData(id);
					}, 3000)
				}
			})
		},
		methods: {
			getData(id) {
				let that = this;
				ticketQueryById({id}).then(res => {
					this.list = res.result.userInfo;
					this.detail = res.result;
					uni.setScreenBrightness({
						value: 1
					})
				}).finally(() => {
					this.loading = false;
				})
			}
		},
		onUnload() {
			let that = this;
			uni.setScreenBrightness({
				value: that.screenBrightness
			})
			clearInterval(this.timer);
		}
	}
</script>

<style lang="scss" scoped>
	.shop-top {
		height: 100rpx;
		background-color: #F5F5F5;
		display: flex;
		align-items: center;
		color: #666;
		padding-left: 16rpx;
		border-radius: 4rpx 4rpx 0 0;
	}

	.couponQrcode-box {
		height: calc(100% - 100rpx);
		background-color: #fff;
		.couponQrcode-box-1 {
			height: 100%;
			display: flex;
			flex-direction: column;
			align-items: center;
			justify-content: center;
			border-radius: 0 0 4rpx 4rpx;
			.qr-mask {
				width: 480rpx;
				height: 480rpx;
				position: absolute;
				left: 0;
				top: 0;
				background-color: rgba(0,0,0,0.9);
				z-index: 10;
				text-align: center;
				line-height: 480rpx;
				color: #fff;
				font-size: 44rpx;
			}
		}
	}
</style>

